{extend name="../../base/view/common/base" /}
{block name="body"}
<div class="layui-form p-page">
    <h3 class="pb-3">
        {if condition="isset($detail.id)"}编辑{else /}新增{/if}联系电话
    </h3>
    <form class="layui-form" action="/lawcase/court/addphone" method="post">
        {if condition="isset($detail.id)"}
        <input type="hidden" name="id" value="{$detail.id}">
        {/if}
        <input type="hidden" name="court_id" value="{$court_id}">
        <div class="layui-form-item">
            <label class="layui-form-label">法院电话</label>
            <div class="layui-input-block">
                <input type="text" name="phone" required lay-verify="required" autocomplete="off" class="layui-input" value="{$detail.phone|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话描述</label>
            <div class="layui-input-block">
                <input type="text" name="description" autocomplete="off" class="layui-input" value="{$detail.description|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script>
function gouguInit() {
    layui.use('form', function(){
        var form = layui.form;
            // 监听提交
            form.on('submit(formDemo)', function(data){
                $.ajax({
                    url: data.form.action,
                    type: 'POST',
                    data: data.field,
                    dataType: 'json',
                    success: function(res){
                        if(res.code == 0) {
                            layer.msg(res.msg || '{if condition="isset($detail.id)"}编辑{else /}新增{/if}成功', {icon: 1}, function(){
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                parent.layui.table.reload('dataTable'); // 刷新父页面的电话列表
                            });
                        } else {
                            layer.msg(res.msg || '操作失败', {icon: 2});
                        }
                    },
                    error: function(xhr){
                        var res = xhr.responseJSON || {};
                        layer.msg(res.msg || '请求失败', {icon: 2});
                    }
                });
                return false; // 阻止表单跳转
        });
    });
}
</script>
{/block}